home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
machack
/
Hacks97
/
WarriorsProgress.sit
/
Warrior’s Progress
/
source code
/
Source
/
Libraries
/
Idle
/
Postponer.cp
< prev
next >
Wrap
Text File
|
1997-06-28
|
982b
|
70 lines
// Postponer.cp
#ifndef Postponer_h
#include "Postponer.h"
#endif
#ifndef Method_h
#include "Method.h"
#endif
Postponer::Postponer( const Method& theMethod )
: link( this ),
perform( theMethod )
{
TheList();
}
Postponer::~Postponer()
{
}
ListOf< Postponer >& Postponer::TheList()
{
static ListOf< Postponer > list;
return list;
}
void Postponer::Schedule()
{
Assert( !Pending() );
TheList().Add( link, afterEnd );
}
void Postponer::Cancel()
{
Assert( Pending() );
TheList().Remove( link );
}
void Postponer::Flush()
{
if ( Pending() )
{
Cancel();
this->perform();
}
}
void Postponer::Execute( Tick stop )
{
ListOf< Postponer >& list( TheList() );
while ( !list.IsEmpty() )
{
Postponer *p = list.First()->Target();
list.Remove( p->link );
p->perform();
if ( Tick::Now() >= stop )
break;
}
}
bool Postponer::CanSleep()
{
return TheList().IsEmpty();
}
#include "ListLink.cp"
#include "ListOf.cp"